package com.sky.loveshop.controller;

import com.sky.loveshop.entity.Result;
import com.sky.loveshop.entity.exception.BizException;
import com.sky.loveshop.service.IotService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author xcy
 * @version V1.0
 * @description iot操作设备相关接口
 * @date 2024/9/8 20:13
 */
@Slf4j
@RestController
@RequestMapping("/iot")
public class IotController {

    @Resource
    private IotService iotService;

    /**
     * 骑手核销完成后开门(前端程序自动调用)
     */
    @GetMapping("/openDoor")
    public Result<String> openDoor(Integer shopId) throws BizException {
        log.info("openDoorAfterCheck 骑手核销完成后开门 shopId={}", shopId);
        String result = iotService.openDoorAfterCheck(shopId);
        return Result.success(result);
    }

    /**
     * 用户线下购买支付后开门(前端程序自动调用)
     */
    @GetMapping("/openDoorAfterPay")
    public Result<String> openDoorAfterPay(Integer shopId) throws BizException {
        log.info("openDoorAfterPay 用户线下购买支付后开门 shopId={}", shopId);
        String result = iotService.openDoorAfterPay(shopId);
        return Result.success(result);
    }

    /**
     * 后台管理系统远程开门
     */
    @GetMapping("/openDoorByAdmin")
    public Result<String> openDoorByAdmin(Integer shopId) throws BizException {
        log.info("openDoorByAdmin 后台管理系统远程开门 shopId={}", shopId);
        String result = iotService.openDoorByAdmin(shopId);
        return Result.success(result);
    }

    /**
     * 开启警报
     */
    @GetMapping("/openAlarm")
    public Result<String> openAlarm(Integer shopId) {
        log.info("openAlarm 开启警报 shopId = {}", shopId);
        String result = iotService.openAlarm(shopId);
        return Result.success(result);
    }

    /**
     * 切换感应模式
     */
    @GetMapping("/switchSensor")
    public Result<String> switchSensor(Integer shopId) {
        log.info("switchSensor 切换感应模式 shopId = {}", shopId);
        String result = iotService.switchSensor(shopId);
        return Result.success(result);
    }

    /**
     * 切换扫码模式
     */
    @GetMapping("/switchScan")
    public Result<String> switchScan(Integer shopId) {
        log.info("switchScan 切换扫码模式 shopId = {}", shopId);
        String result = iotService.switchScan(shopId);
        return Result.success(result);
    }

    /**
     * 根据门店id将门禁开关功能强制失效(目的：将不良用户强制锁在店内使其无法开门)
     */
    @GetMapping("/forceDisableDoor")
    public Result<Integer> forceDisableDoor(Integer shopId) {
        log.info("forceDisableDoor 强制锁门 shopId = {}", shopId);
        Integer result = iotService.forceDisableDoor(shopId);
        return Result.success(result);
    }

    /**
     * 取消根据门店id将门禁开关功能强制失效
     */
    @GetMapping("/removeForceDisableDoor")
    public Result<Integer> removeForceDisableDoor(Integer shopId) {
        log.info("removeForceDisableDoor 取消强制锁门 shopId = {}", shopId);
        Integer result = iotService.removeForceDisableDoor(shopId);
        return Result.success(result);
    }

}
